<template>
    <div class="cmdcfg" title="500毫秒检测一次时间">
        等待到:
        <el-time-picker v-model="timer" value-format="HH:mm:ss" style="width:120px" placeholder="选择时间" size="mini">
        </el-time-picker>
    </div>
</template>


<script>

export default {
    props: {
        cmdInfo: { type: Object, default: {} },
        devInfo:{ type: Object, default: {} },
    },
    data() {
        return {
            timer : this.cmdInfo.timer || "",
            sTimer : null,
        };
    },
    inject: ['doDevCmd','doNextCmd'],
     

    mounted() {
        
        this.$once('hook:beforeDestroy', () => {            
            clearInterval(this.sTimer);
        })
    },

    methods: {
        setByDevInfo(){
            if(this.cmdInfo.timer) this.waitTime = this.cmdInfo.timer;
        },
        saveCmd(){
            this.cmdInfo.timer = this.timer;
        },
        preCheck(){
            if(!this.timer){
                this.$message.error("请输入等待时间点")
                return false;
            }
            return true;
        },
        runCmd(isOnce){
            if(!this.preCheck()){
                this.$emit("stopRun")
                return;
            }
            clearInterval(this.sTimer);
            this.sTimer=setInterval(()=>{
                var curtime = this.$dayjs().format("HH:mm:ss");
                if(curtime>this.timer){
                    this.stopCmd();
                    this.$emit("stopRun")
                    if(isOnce!==true) this.doNextCmd();
                }
            },500)
        },
        stopCmd(){
            clearInterval(this.sTimer);
            this.$emit("stopRun")
        }
    }
}
</script>

<style lang="less" scoped>
    .cmdcfg{
        display: inline-block;
    }
</style>
